package org.example.dormsystem.mapper;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;
import org.example.dormsystem.pojo.Student;

import java.util.List;

@Mapper
public interface StudentMapper {

    @Select("select * from student where id = #{studentId}")
    Student findStudentByStudentId(Integer studentId);

    @Insert("insert into student(id ,studentName) values(#{studentId},#{studentName})")
    void add(Integer studentId, String studentName);//添加学生

    @Insert("insert into changeRecord(studentId,studentName,dormitoryNumber,bedNumber,telNumber,adminNumber,changeTime) " +
            "values(#{id},#{studentName},#{dormitoryNumber},#{bedNumber},#{telNumber},#{adminNumber},now())")
    void submitStudent(Student student);//提交审核



    @Select("select * from student where dormitoryNumber = #{dormitoryNumber}")
    List<Student> findStudentByDormitoryNumber(String dormitoryNumber);

    @Update("update student set " +
            "studentName = #{studentName}," +
            "dormitoryNumber = #{dormitoryNumber}," +
            "bedNumber = #{bedNumber}," +
            "telNumber = #{telNumber}," +
            "adminNumber = #{adminNumber} " +
            "where id = #{id}")
    void updateStudent(Student student);//更新学生信息（审核过后）

    @Select("select * from student")
    List<Student> getAll();
}
